SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW [dbo].[TDCHEQ_LIST]  /* Tab Lista de Cheques Devueltos */        
AS        
Select  T1.CO_EMPR, T1.TI_ENTI, T1.CO_ENTI, T1.CO_BANC_CHEQ,        
'CHE' AS CO_TIPO_DOCU, T1.NU_CHEQ,  T2.CO_MONE,        
T1.IM_MOVI, T1.FE_DISP, T1.FE_DIFE, T1.FE_OPER,         
T1.CO_BANC, T1.NU_CNTA_BANC        
From    TCMOVI_BANC T1, TMCNTA_BANC T2        
Where T1.TI_ENTI Is Not Null        
And Len(T1.TI_ENTI) > 0        
And T1.CO_ENTI Is Not Null        
And Len(T1.CO_ENTI) > 0        
And T1.CO_BANC_CHEQ Is Not Null        
And Len(T1.CO_BANC_CHEQ) > 0        
And T1.NU_CHEQ Is Not Null        
And Len(T1.NU_CHEQ) > 0        
And T1.TI_MOVI_BANC = 'I'        
And T1.TI_SITU != 'ANU'        
And T1.CO_EMPR = T2.CO_EMPR        
And T1.CO_BANC = T2.CO_BANC        
And T1.NU_CNTA_BANC = T2.NU_CNTA_BANC         
UNION ALL        
Select  T2.CO_EMPR, T1.TI_ENTI, T1.CO_ENTI, T1.CO_BANC_CHEQ,        
'CHE' AS CO_TIPO_DOCU, T1.NU_CHEQ, T1.CO_MONE,        
T1.IM_CONV, T1.FE_DISP, T1.FE_DIFE, T2.FE_OPER,         
T1.CO_BANC, T1.NU_CNTA_BANC        
From TDCHEQ_BANC T1, TCMOVI_BANC T2        
Where  T1.TI_ENTI Is Not Null        
And Len(T1.TI_ENTI) > 0        
And T1.CO_ENTI Is Not Null        
And Len(T1.CO_ENTI) > 0        
And T1.CO_BANC_CHEQ Is Not Null        
And Len( T1.CO_BANC_CHEQ) > 0        
And T1.NU_CHEQ Is Not Null        
And Len( T1.NU_CHEQ) > 0        
And T1.TI_MOVI_BANC = 'I'        
And T1.CO_EMPR = T2.CO_EMPR        
And T1.CO_BANC = T2.CO_BANC        
And T1.NU_CNTA_BANC = T2.NU_CNTA_BANC        
And T1.AA_BNCO = T2.AA_BNCO        
And T1.MM_BNCO = T2.MM_BNCO        
And T1.TI_MOVI_BANC = T2.TI_MOVI_BANC        
And T1.NU_COMP_BANC = T2.NU_COMP_BANC        
And T2.TI_SITU != 'ANU'

GO
